#include <stdio.h>
#include <unistd.h>
#include <pthread.h>    // pthread

#include "logging.h"

#include "test_logging.h"

void* thread_test_logging(void *args)
{
    int i = 0;
    int thread_id = *(int*) args;

    for(i = 0; i < 4*1024; i++)
    {
        if(i%((thread_id+100)*(1+thread_id)) == 0) printf("thread[%d], i = %d\r", thread_id, i);
        usleep(1111);
        logging(i % LOG_LEVEL_INVALID, "thread[%d], i = %d", thread_id, i);
    }
    
    return 0;
}

int test_logging(void)
{
    int i = 0;
    int id[10] = {0};
    pthread_t threads[10];

    printf("        test_logging()\n");

    logging_init();

    for(i = 0; i < sizeof(id)/sizeof(id[0]); i++)
    {
        id[i] = i + 1;
        pthread_create(&threads[i], NULL, thread_test_logging, id+i);
    }

    for(i = 0; i < sizeof(id)/sizeof(id[0]); i++)
    {
        pthread_join(threads[i], NULL);
    }
    puts("\n");

    logging_exit();

    return 0;
}

